package com.cmw.controller.web;

import com.cmw.core.base.exception.ServiceException;
import com.cmw.entity.Student;
import com.cmw.service.inter.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

/**
 * 首页Controller
 * Created by Administrator on 2017-05-17.
 */
@Controller
public class IndexController extends BaseController{
    @Resource(name="studentService")
    StudentService studentService;
    /**
     * 首页
     * @return
     */
    @RequestMapping("/")
    public String index(HttpSession session,Map<String,Object> map) {
        Student student = studentService.get(1L);
        session.setAttribute("currstudent", student);
        map.put("sessionId",session.getId());
        LOG.error("sessionId="+session.getId());
        return "/index";
    }

    /**
     * 首页
     * @return
     */
    @RequestMapping("/home")
    public String home() throws Exception {
        if(1==1) throw new ServiceException("错误...");
        return "/index";
    }

    /**
     * json 异常返回必须 ServiceException
     * @return
     */
    @RequestMapping(value = "/sexception")
    @ResponseBody
    public String sexception() throws Exception {
        if(1==1) throw new ServiceException("错误...");
        return "/index";
    }
}
